package com.google.gwt.mobile.widgets.utils;

/**
 * The Class Point.
 */
public class Point {

  private double x, y;

  /**
   * Instantiates a new point.
   * 
   * @param c the c
   */
  public Point(final Point c) {
    x = c.x;
    y = c.y;
  }

  /**
   * X.
   * 
   * @return the double
   */
  public double X() {
    return x;
  }

  /**
   * Y.
   * 
   * @return the double
   */
  public double Y() {
    return y;
  }

  /**
   * Instantiates a new point.
   * 
   * @param x the x
   * @param y the y
   */
  public Point(final double x, final double y) {
    Set(x, y);
  }

  /**
   * Sets the.
   * 
   * @param x the x
   * @param y the y
   * @return the point
   */
  public Point Set(final double x, final double y) {
    this.x = x;
    this.y = y;
    return this;
  }

  /*
   * (non-Javadoc)
   * 
   * @see java.lang.Object#equals(java.lang.Object)
   */
  @Override
  public boolean equals(final Object obj) {
    if (!(obj instanceof Point)) {
      return false;
    }
    Point c = (Point) obj;
    return (x == c.x) && (y == c.y);
  }

  /*
   * (non-Javadoc)
   * 
   * @see java.lang.Object#hashCode()
   */
  @Override
  public int hashCode() {
    return (int) x ^ (int) y;
  }

  /**
   * Minus.
   * 
   * @param c the c
   * @return the point
   */
  public Point minus(final Point c) {
    this.x -= c.x;
    this.y -= c.y;
    return this;
  }

  /**
   * Plus.
   * 
   * @param c the c
   * @return the point
   */
  public Point plus(final Point c) {
    this.x += c.x;
    this.y += c.y;
    return this;
  }

  /**
   * Clone.
   * 
   * @param c the c
   * @return the point
   */
  public Point clone(final Point c) {
    this.x = c.x;
    this.y = c.y;
    return this;
  }

  /*
   * (non-Javadoc)
   * 
   * @see java.lang.Object#toString()
   */
  @Override
  public String toString() {
    return "(" + x + ", " + y + ")";
  }
}
